package com.zsc.rediscli;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;

public class RedisPipeline {

    public static void main(String[] args) {
//        System.out.println(noPipeline());  //1792
        System.out.println(pipeline());     //153

    }

    public static long noPipeline(){
        long start = System.currentTimeMillis();
        Jedis jedis = new Jedis("192.168.56.106",6379);
        for (int i=0;i<10000; i++){
            jedis.hset("hsetkey"+i,"field"+i,"value"+i);
        }
        return System.currentTimeMillis()-start;
    }

    public static long pipeline(){
        long start = System.currentTimeMillis();
        Jedis jedis = new Jedis("192.168.56.106",6379);
        for (int i=0;i<100; i++){
            Pipeline pipelined = jedis.pipelined();
            for (int j = i*100; j <(i+1)*100 ; j++) {
                pipelined.hset("hsetkey","field"+j,"value"+j);
            }
            pipelined.syncAndReturnAll();
        }
        return System.currentTimeMillis()-start;
    }
}
